<?php 
class IndexAction extends BaseAction {
    //后台框架页
    public function index() {
    	$this->assign('channel', $this->_getChannel());
    	$this->assign('menu',    $this->_getMenu());
        $this->display();
    }
    
    //后台首页
    public function main() {
    	echo '<h2>这里是后台首页</h2>';
    	$this->display();
    }
    
    protected function _getChannel() {
    	return array(
    		'index'				=>	'首页',
    		'global'			=>	'全局',
    		'content'			=>	'内容',
    		'dictionary'		=>	'字典',
    		'user'				=>	'人员',
    		'partners'			=>	'商户',
    		'goods'				=>	'商品',
    		'price'				=>	'价格',
    		'shelf'				=>	'货架',
    		'orders'			=>	'订单',
    		'payment'			=>	'支付',
    		'cashcoupon'		=>	'代金券',
    		'advisory'			=>	'问答',
    		'statistics'		=>	'统计',
    		'extension'			=>	'工具',
    	);
    }
    
    protected function _getMenu() {
    	$menu = array();
    	//注意顺序！！
    
		
    	// 后台管理首页
    	$menu['index'] 		=   array(
    		'首页'			=>	array(
    			'首页'		=>	U('/Index/statistics'),
    		),
    	);
    	
    	//全局
    	$menu['global'] 	=   array(
    		'全局配置'		=>  array(
    			'站点配置'	=>	U('/Global/siteopt'),
    			'注册配置'	=>	U('/Global/register'),
    			'邀请配置'	=>	U('/Global/invite'),
    			//'积分配置'	=>	U('/Global/credit'),
    			'公告配置'	=>	U('/Global/announcement'),
    			'邮件配置'	=>	U('/Global/email'),
    			'短信配置'	=>	U('/SmsManage/sms'),
    			'附件配置'	=>	U('/Global/attachConfig'),
    			'平台配置'	=>	U('/Global/platform'),
    		),
    	);
    	
    	//内容
    	$menu['content'] 	=   array(
    		'内容管理'		=>  array(
    							'首页管理'	=>	U('/Global/hp'),
								'广告管理'	=>	U('/Content/ad'),
				    			//'表情管理'	=>	U('/Content/expression'),
				    			//'模板管理'	=>	U('/Content/template'),
				    			'附件管理'	=>	U('/Content/attach'),
				    			//'评论管理'	=>	U('/Content/comment'),
				    			//'短消息管理'	=>	U('/Content/message'),
				    			'通知管理'	=>	U('/Content/notify'),
				    			//'动态管理'	=>	U('/Content/feed'),
				    			'文档管理'	=>	U('/Global/document'),
    							'彩信图片'	=>	U('/SmsTemplet/index'),
				    		),
			'模板管理'	=>	array(
    								'短信模板'	=>	U('/Content/template'),
    								'彩信模板'	=>	U('/Content/template'),
									'邮件模板'	=>	U('/Content/template'),
								),
			
    	);
    	
    	$listdict = service('Dict')->selectByParentId(0);
    	$ary_dict['根分类表'] = U('/Dict/index');
			foreach($listdict as $vo1){
					$ary_dict[$vo1['desc']] = U('/Dict/index',array('parentId'=>$vo1['id']));
			}
    	
    	$menu['dictionary']	=	array(
    		'地区'			=>	array(
    			'地区管理'	=>	U('/Tool/area'),
    			'热门地点'	=>	U('/AreaPopular/index'),
    			'添加地点'	=>	U('/AreaPopular/add'),
    		),
    		'分类'			=>	$ary_dict,
    	);
    	
    	//用户
    	$menu['user']		=	array(
    		'用户'			=>	array(
    			'用户列表'	=>	U('/User/user'),
    			//'用户组管理'	=>	U('/User/userGroup'),
    			//'资料配置'	=>	U('/User/setField'),
    			//'消息群发'	=>	U('/User/message'),
    		),
    		'管理员'			=>	array(
    			'管理员列表'	=>	U('/User/node'),
    			//'权限管理'	=>	U('/User/popedom'),
    		),
    		/**
    		'验证员'			=>	array(
    			'验证员列表'	=>	U('/User/node'),
    			//'权限管理'	=>	U('/User/popedom'),
    		),
    		**/
    	);
    	
    	//商户
    	$menu['partners'] 		=	array(
    		'商户管理'		=>	array(
    			'商户列表'	=>	U('/Partner/index'),
    			'商户录入'	=>	U('/Partner/addPartner'),
    		),
    	);
    	
    	//商品
    	$menu['goods'] 		=	array(
    		'商品管理'		=>	array(
    			'商品列表'	=>	U('/Goods/index'),
    			'新增商品'	=>	U('/Goods/add'),
    		),
    	);
    	
    	//价格
    	$menu['price']	=	array(
    		'价格'			=>	array(
    			'价格列表'	=>	U('/Price/index'),
    			'新增价格'	=>	U('/Price/add'),
    		),
    	);
    	
    	//货架
    	$menu['shelf'] 		=	array(
    		'货架管理'		=>	array(
    			'货架查询'	=>	U('/Shelf/index',array('shelfstatus'=>'on')),
    			'新增上架'	=> 	U('/Shelf/puton'),
    		),
    	);
    	
    	//订单
    	$menu['orders'] 		=	array(
    		'订单管理'		=>	array(
    			'订单管理'	=>	U('/Order/index'),
    			'礼券管理'	=>	U('/Order/coupon'),
    			'礼券详情'	=>	U('/Order/couponDetail'),
    		),
    	);
    	
    	$menu['advisory'] 		=	array(
    		'问答管理'		=>	array(
    			'咨询管理'	=>	U('/Advisory/index',array('sortcode'=>'question')),
    			'报错管理'	=>	U('/Advisory/index',array('sortcode'=>'error')),
    			'建议详情'	=>	U('/Advisory/index',array('sortcode'=>'suggest')),
    		),
    	);
    	
    	
    	$menu['payment'] 		=	array(
    		'支付管理'		=>	array(
    			'支付记录'	=>	U('/Payment/index'),
    		),
    	);
    	
    	$menu['cashcoupon'] 	=	array(
    		'代金券管理'		=>	array(
    			'代金券查询'	=>	U('/Cashcoupon/index'),
    			'券号码查询'	=>	U('/Cashcoupon/code'),
    			'代金券生成'	=>	U('/Cashcoupon/createCC'),
    			'代金券分类'	=>	U('/Cashcoupon/rule'),
    		),
    	);
    	
 
    	$menu['statistics']	=	array(
    		'统计'			=>	array(
    			'销售统计'	=>	U('/Tool/backup'),
    			'货架统计'	=>	SITE_URL . '/Admin/cleancache.php?all',
    			'商品统计'	=>	U('/Tool/area'),
    			'价格走势'	=>	U('/Category/index'),
    		),
    	);
    	
    	$menu['extension']	=	array(
    		'工具'			=>	array(
    			'数据备份'	=>	U('/Tool/backup'),
    			'缓存更新'	=>	SITE_URL . '/Admin/cleancache.php?all',
    			'任务管理'	=>	SITE_URL . '/Admin/cleancache.php?all',
    			'刷新数据'	=>	U('/Tool/backup'),
    			'批量发送'	=>	U('/Tool/batchsend'),
    		),
    	);
    	
    	return $menu;
    }

    
	// 统计信息
	public function statistics() {
		$statistics = array();
		
		/** 为了防止与应用别名重名，“服务器信息”、“用户信息”、“开发团队”作为key前面有空格 **/
		
		// 服务器信息
		$serverInfo['核心版本']        	= 'QUICK 1.0';
        $serverInfo['服务器系统及PHP版本']	= PHP_OS.' / PHP v'.PHP_VERSION;
        $serverInfo['服务器软件'] 			= $_SERVER['SERVER_SOFTWARE'];
        $serverInfo['最大上传许可']     	= ( @ini_get('file_uploads') )? ini_get('upload_max_filesize') : '<font color="red">no</font>';
        
        $mysqlinfo = M('')->query("SELECT VERSION() as version");
        $serverInfo['MySQL版本']			= $mysqlinfo[0]['version'] ;
        
        $t = M('')->query("SHOW TABLE STATUS LIKE '".C('DB_PREFIX')."%'");
        foreach ($t as $k){
            $dbsize += $k['Data_length'] + $k['Index_length'];
        }
        $serverInfo['数据库大小']			= byte_format( $dbsize );
        $statistics[' 服务器信息'] = $serverInfo;
        unset($serverInfo);
        
        // 主要运行系统参数
        $param['数据库连接配置'] = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
        $param['数据库名称'] = C('DB_NAME');
        $param['数据库地址'] = C('DB_HOST');
        $param['登陆用户名'] = C('DB_USER');
        
        $param['定时任务参数配置'] = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
        $param['启动定时任务'] = C('KMISSION_SHUTDOWN')==false?'已启动运行':'已关闭';
        $param['任务内部间隔'] = C('KMISSION_INTERVAL').' 秒';
        $param['任务运行密码'] = C('KMISSION_RUNPW');
        
        $param['短信发送参数配置'] = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
        $param['模拟短信发送'] = C('SMS_SIMULATION')==false?'未开启':'已开启';
        $param['模拟彩信发送'] = C('MMS_SIMULATION')==false?'未开启':'已开启';
        $param['删除彩信ZIP'] = C('MMS_ZIP_DELETE')==false?'未开启':'已开启';
        
        $param['后台管理参数配置'] = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~';
        $param['登录验证邮件'] = C('ADMIN_SEND_LOGIN_EMAIL')==false?'不发送':'需发送';
        $param['订单彻底删除'] = C('ADMIN_OPEN_ORDER_CLEAN')==false?'未开启':'已开启';
        
        $statistics[' 系统配置'] = $param;
        unset($param);
        
        
        // 用户信息
        //$user['当前在线'] = '***';
        $user['总用户数'] = M('User')->where("`is_active` = 1 AND `enable` = 'Y'")->count();
        $user['今日注册'] = M('User')->where("`is_active` = 1 AND `enable` = 'Y' AND `ctime`> {:time()}")->count();
        $user['今日注册'] = empty($user['今日注册'])?0:$user['今日注册'];
        $statistics[' 用户信息'] = $user;
        unset($user);
        
      
        // 开发团队
        /**
        $statistics[' 开发团队'] = array(
        	'版权所有'	=> '<a href="http://www.XXX.com" target="_blank">XXX软件（北京）有限公司</a>',
        	'项目经理'	=> 'XXX',
        	'美工设计'	=> 'XXX',
        	'开发团队'	=> 'XXX、XXX、XXX、XXX',
        );
        **/
        $this->assign('statistics', $statistics);
        $this->display();
	}
}